#!/bin/bash
set -ueo pipefail

for AMR in "${TRAIN_FILE}" "${DEV_FILE}" "${TEST_FILE}"
do
    inputfile="${AMR}.snt"
    outputfile="${AMR}.snt.IllinoisNER.tmp"
    configfile="$JAMR_HOME/scripts/preprocessing/IllinoisNER.config"
    cpath="$ILLINOIS_NER_JAR:$ILLINOIS_NER/target/classes:$ILLINOIS_NER/target/dependency/*"
    cat "$inputfile" | sed $'s/$/\\\n####\\\n/' > "$inputfile".tmp
    pushd "$ILLINOIS_NER"
    java -classpath  "${cpath}" -Xmx8g edu.illinois.cs.cogcomp.LbjNer.LbjTagger.NerTagger -annotate "$inputfile".tmp "${outputfile}" "${configfile}"
    popd
    # The awk command drops the last line, see http://askubuntu.com/questions/475694/awk-command-to-print-all-the-lines-except-the-last-three-lines
    cat "$outputfile" | sed $'s/ #### /\\\n/g' | "$SCALA" "$JAMR_HOME/src/IllinoisNERConvert" | awk '{l[NR] = $0} END {for (i=1; i<=NR-1; i++) print l[i]}' > "${AMR}.snt.IllinoisNER"
    rm "$outputfile"
    rm "$inputfile".tmp
done

